package com.lanou.remember.controller;

import com.lanou.k12.entity.Question;
import com.lanou.k12.entity.ResultObject;
import com.lanou.remember.service.IQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api("学习模块")
@RestController
@RequiresAuthentication
@RequestMapping(method = RequestMethod.POST)
public class QuestionController {

    @Autowired
    IQuestionService service;


    @RequestMapping("/findProcess")
    @ApiOperation(value = "学习进度", notes = "返回用户当前已学习，题库总数")
    public ResultObject findProcess() {
        return service.findProcess();
    }

    @RequestMapping("/addQuestion")
    @ApiOperation(value = "题库新增题", notes = "上传题接口")
    public ResultObject addQuestion(Question question) {
        return service.addQuestion(question);
    }

    @RequestMapping("/findQuestionByStatus")
    @RequiresRoles("admin")
    @ApiOperation(value = "查找待审核题", notes = "管理员登录时可以访问")
    public ResultObject findQuestionByStatus(int page, int size) {
        return service.findQuestionByStatus(page,size);
    }

    @RequestMapping("/deleteQuestion")
    @RequiresRoles("admin")
    @ApiOperation(value = "修改题可见性", notes = "管理员登录时可以访问")
    public ResultObject deleteQuestion(int qid) {
        return service.deleteQuestion(qid);
    }


    @RequestMapping("/updateQuestion")
    @RequiresRoles("admin")
    @ApiOperation(value = "修改题", notes = "角色为管理员时可以访问该接口")
    public ResultObject updateQuestion(Question question) {
        return service.updateQuestion(question);
    }

    @RequestMapping("/findQuestionByKeyWord")
    @ApiOperation(value = "关键字查题", notes = "根据输入的关键字找到需要定位的题")
    public ResultObject findQuestionByKeyWord(Integer id, String question, String answer) {
        return service.findQuestionByKeyWord(id,question,answer);
    }

    @RequestMapping("/findQuestion")
    @ApiOperation(value = "学新题", notes = "根据用户学习记录查到当前应学习的题")
    public ResultObject findQuestion(int page, int size) {
        return service.findQuestion(page,size);
    }
}
